/*
    This file is part of Posixcpp library.

    Posixcpp library is free software: you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public License
    as published by the Free Software Foundation, either version 3 of
    the License, or (at your option) any later version.

    Posixcpp library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU LesserGeneral Public
    License along with Posixcpp library. If not, see
    <http://www.gnu.org/licenses/>.
 */

/**
 * @file posix_spinlock.hpp
 * @brief POSIX spinlock and related datatypes
 */

#ifndef POSIX_THREADS_SPINLOCK_INCLUDED
#define POSIX_THREADS_SPINLOCK_INCLUDED

#include <pthread.h>

#include "posix_threads_ilock.hpp"

namespace posix
{
namespace threads
{

/**
 * @class SpinLock
 * @brief POSIX threads spinlock primitive
 */
class SpinLock final : public ILock
{
public:
    SpinLock();
    ~SpinLock();

    void lock();
    void unlock();
    bool tryLock();

    pthread_spinlock_t & handle()
    {
        return m_handle;
    }

    const pthread_spinlock_t & handle() const
    {
        return m_handle;
    }
private:
    pthread_spinlock_t m_handle;
};
}
}
#endif // POSIX_THREADS_SPINLOCK_INCLUDED
